package com.neuedu.hcp.controller;



import com.neuedu.hcp.entity.RespBean;
import com.neuedu.hcp.entity.RespPageBean;
import com.neuedu.hcp.entity.Staff;
import com.neuedu.hcp.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 第八组
 * @since 2021-04-26
 */

//http://127.0.0.1:8081/staff/stafflist
@RestController
@RequestMapping("/staff")
public class StaffController {
   @Autowired
    IStaffService staffService;

    /**
     * 分页数据
     * @param currentPage
     * @param size
     * @param staff
     * @return
     */
    @GetMapping("/stafflist")
    public RespPageBean list(@RequestParam(defaultValue = "1") Integer currentPage,
                             @RequestParam(defaultValue = "10") Integer size,
                             Staff staff){
        return staffService.getStaffListByPage(currentPage,size,staff);
    }

    /**
     * 插入
     * @param staff
     * @return
     */
    @GetMapping("/insert")
    public RespBean insert(Staff staff){
        if (staffService.insert(staff) <= 0) {
            return RespBean.error("插入失败");
        }
        return RespBean.success("插入成功");
    }


    @PostMapping("/update")
    public RespBean update(@RequestBody Staff staff){
        if(staffService.updateById(staff)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    /**
     * 删除
     * @param staffId
     * @return
     */
    @GetMapping("/delete")
    public RespBean delete( @RequestParam Integer staffId){
        if(staffService.removeById(staffId)){
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }



}
